package o;

import android.content.Context;
import android.content.Intent;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.os.SystemClock;
import com.huawei.appgallery.assistantdock.subaccount.GameSubAccActivity;
import com.huawei.appgallery.assistantdock.subaccount.GameSubAccountSwitchActivity;
import com.huawei.appgallery.foundation.account.bean.UserSession;
import com.huawei.appgallery.serverreqkit.api.bean.BaseResponseBean;
import com.huawei.appgallery.serverreqkit.api.bean.ResponseBean;
import com.huawei.appgallery.serverreqkit.api.listener.IServerCallBack;
import com.huawei.gamebox.plugin.gameservice.bean.GameInfo;
import com.huawei.gamebox.plugin.gameservice.bean.GameSubAcct;
import com.huawei.gamebox.plugin.gameservice.bean.GetGameSubAccResp;
import com.huawei.gamebox.plugin.gameservice.db.tables.GameSubAcctRecord;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

public class ezv {
    private static ezv ॱ;
    private boolean ʻ = false;
    private Handler ʼ;
    private GameInfo ˊ = new GameInfo();
    private HashMap<String, fad> ˋ = new HashMap();
    private Context ˎ = null;
    private List<GameSubAcct> ˏ = new ArrayList();
    private long ॱॱ = 0;
    private String ᐝ;

    static class b implements IServerCallBack {
        private b() {
        }

        public void notifyResult(BaseRequest o_cvu, ResponseBean responseBean) {
        }

        public void prePostResult(BaseRequest o_cvu, ResponseBean responseBean) {
        }
    }

    public interface c {
        void ॱ(BaseResponseBean baseResponseBean);
    }

    public static synchronized ezv ॱ() {
        ezv o_ezv;
        synchronized (ezv.class) {
            if (ॱ == null) {
                ॱ = new ezv();
            }
            o_ezv = ॱ;
        }
        return o_ezv;
    }

    public void ˎ(Context context, GameInfo gameInfo, String str, fad o_fad) {
        this.ˊ = gameInfo;
        this.ˎ = context;
        ʻ();
        this.ᐝ = str;
        ˏ(gameInfo, o_fad);
    }

    private void ˏ(GameInfo gameInfo, fad o_fad) {
        if (gameInfo == null || dof.ˋ(gameInfo.getAppId())) {
            Logger.e("GameSubAccManager", "invaild gameInfo");
        } else {
            this.ˋ.put(gameInfo.getAppId(), o_fad);
        }
    }

    private fad ˋ(GameInfo gameInfo) {
        if (gameInfo == null || dof.ˋ(gameInfo.getAppId())) {
            Logger.e("GameSubAccManager", "the gameInfo is null");
            return null;
        } else if (this.ˋ != null && this.ˋ.size() > 0) {
            return (fad) this.ˋ.get(gameInfo.getAppId());
        } else {
            Logger.e("GameSubAccManager", "the [callbackMap] is null");
            return null;
        }
    }

    public void ˊ(ccm o_ccm, final c cVar) {
        cfw.ˎ(ezc.ˋ(this.ˊ, o_ccm), new b(this) {
            final /* synthetic */ ezv ˎ;

            public void notifyResult(BaseRequest o_cvu, ResponseBean responseBean) {
                if (responseBean == null || !(responseBean instanceof GetGameSubAccResp)) {
                    bfr.ˋ(this.ˎ.ˎ, 110045);
                    cVar.ॱ(null);
                } else if (responseBean.getResponseCode() != 0) {
                    switch (responseBean.getResponseCode()) {
                        case 2:
                            bfr.ˋ(this.ˎ.ˎ, 110043);
                            break;
                        case 3:
                            bfr.ˋ(this.ˎ.ˎ, 110044);
                            break;
                        default:
                            bfr.ˋ(this.ˎ.ˎ, 110045);
                            break;
                    }
                    cVar.ॱ(null);
                } else {
                    GetGameSubAccResp getGameSubAccResp = (GetGameSubAccResp) responseBean;
                    if (getGameSubAccResp.getRtnCode_() == 0) {
                        cVar.ॱ(getGameSubAccResp);
                        return;
                    }
                    bfr.ˋ(this.ˎ.ˎ, 110046);
                    cVar.ॱ(null);
                }
            }
        });
    }

    public void ॱ(boolean z) {
        if (ˋ()) {
            this.ʻ = z;
            if (UserSession.getInstance().isLoginSuccessful()) {
                ʽ();
                return;
            }
            if (Logger.ˎ()) {
                Logger.ˏ("GameSubAccManager", "user is not login, start to login");
            }
            eoj.ˋ().ˎ("GameSubAccManager", new AccountBussinessListener(this) {
                final /* synthetic */ ezv ˏ;

                {
                    this.ˏ = r1;
                }

                public void onAccountBusinessResult(ccp o_ccp) {
                    if (o_ccp.ˎ == 102) {
                        this.ˏ.ʽ();
                    }
                    eoj.ˋ().ˊ("GameSubAccManager");
                }
            });
            eod.ॱ(ContentManager.getInstant().getContext());
            return;
        }
        Logger.ˋ("GameSubAccManager", "forbidden show game sub account dialog in a short time");
    }

    public void ˏ() {
        if (ˋ()) {
            this.ʼ.sendMessage(this.ʼ.obtainMessage(1));
        } else {
            Logger.ˋ("GameSubAccManager", "forbidden show game sub account dialog in a short time");
        }
    }

    public boolean ˋ() {
        long uptimeMillis = SystemClock.uptimeMillis();
        long j = uptimeMillis - this.ॱॱ;
        this.ॱॱ = uptimeMillis;
        return j > 1000;
    }

    public void ˋ(GameSubAcct gameSubAcct) {
        ezq.ˏ().ˏ(1, gameSubAcct.ˏ(), gameSubAcct.ˊ(), this.ˊ.getPackageName());
        GameSubAcctRecord ॱ = gameSubAcct.ॱ();
        ॱ.ˎ(String.valueOf(System.currentTimeMillis()));
        ezg.ॱ().ˋ(ॱ);
        ˏ(gameSubAcct.ˏ());
    }

    private void ˏ(String str) {
        fad ˋ = ˋ(this.ˊ);
        if (ˋ != null) {
            try {
                ˋ.ˋ(this.ᐝ, str);
            } catch (Throwable e) {
                Logger.ˋ("GameSubAccManager", "notify the switch sub-accout exception", e);
            }
        } else if (Logger.ˎ()) {
            Logger.ˏ("GameSubAccManager", "mCallback is null");
        }
    }

    private void ʽ() {
        ˊ(null, new c(this) {
            final /* synthetic */ ezv ॱ;

            {
                this.ॱ = r1;
            }

            public void ॱ(BaseResponseBean baseResponseBean) {
                this.ॱ.ˏ(null);
                if (baseResponseBean != null && baseResponseBean.getRtnCode_() == 0) {
                    this.ॱ.ˏ = ((GetGameSubAccResp) baseResponseBean).ˎ();
                    this.ॱ.ᐝ();
                    this.ॱ.ʼ.sendMessage(this.ॱ.ʼ.obtainMessage(0));
                }
            }
        });
    }

    private void ᐝ() {
        if (this.ˏ == null || this.ˊ == null) {
            Logger.e("GameSubAccManager", "the params is null when call method [setLoginTime]");
            return;
        }
        List ॱ = ezg.ॱ().ॱ(ezq.ˏ().ˏ(this.ˊ.getPackageName()), this.ˊ.getAppId());
        for (GameSubAcct gameSubAcct : this.ˏ) {
            String str = "";
            if (ॱ != null) {
                str = ॱ(gameSubAcct, ॱ);
            }
            gameSubAcct.ˏ(str);
        }
    }

    private String ॱ(GameSubAcct gameSubAcct, List<GameSubAcctRecord> list) {
        for (GameSubAcctRecord gameSubAcctRecord : list) {
            String ॱ = gameSubAcctRecord.ॱ();
            if (dof.ॱ(ॱ)) {
                ॱ = gameSubAcctRecord.ˋ();
            }
            if (ॱ != null && ॱ.equals(gameSubAcct.ˏ())) {
                return gameSubAcctRecord.ˎ();
            }
        }
        return "";
    }

    private void ˏ(Context context) {
        if (context == null) {
            Logger.e("GameSubAccManager", "the param [context] is null");
        } else if (this.ʻ) {
            fam.ॱ().ˎ(context, GameSubAccActivity.class, new Intent(context, GameSubAccActivity.class), true);
        } else {
            bga.ॱ().ˏ(this.ˊ, GameSubAccActivity.class, null);
        }
    }

    private void ˎ(Context context) {
        if (context == null) {
            Logger.e("GameSubAccManager", "the param [context] is null");
            return;
        }
        String packageName = this.ˊ.getPackageName();
        Intent intent = new Intent(this.ˎ, GameSubAccountSwitchActivity.class);
        intent.putExtra("packageName", packageName);
        fam.ॱ().ˎ(this.ˎ, GameSubAccountSwitchActivity.class, intent, true);
    }

    private void ʻ() {
        this.ʼ = new Handler(this, Looper.getMainLooper()) {
            final /* synthetic */ ezv ˏ;

            public void handleMessage(Message message) {
                if (message.what == 0) {
                    this.ˏ.ˏ(this.ˏ.ˎ);
                } else if (message.what == 1) {
                    this.ˏ.ˎ(this.ˏ.ˎ);
                }
            }
        };
    }

    public List<GameSubAcct> ˊ() {
        return this.ˏ;
    }

    public GameInfo ˎ() {
        return this.ˊ;
    }

    public void ॱ(GameInfo gameInfo) {
        this.ˊ = gameInfo;
    }
}
